


#ifndef PF_DIMENSION_H
#define PF_DIMENSION_H

#include "pf_entitycontainer.h"
#include "lx_Export.h"
/**
 * Holds the data that is common to all dimension entities.
 */
class LX_EXPORT PF_DimensionAttribute : public PF_Flags {
public:
    /**
     * Default constructor. Leaves the data object uninitialized.
     */
    PF_DimensionAttribute() {}

    /**
     * Constructor with initialisation.
     *
     * @param definitionPoint Definition point.
     * @param middleOfText Middle point of dimension text.
     * @param valign Vertical alignment.
     * @param halign Horizontal alignment.
     * @param lineSpacingStyle Line spacing style.
     * @param lineSpacingFactor Line spacing factor.
     * @param text Text string entered explicitly by user or null
     *         or "<>" for the actual measurement or " " (one blank space).
     *         for supressing the text.
     * @param style Dimension style name.
     * @param angle Rotation angle of dimension text away from 
     *         default orientation.
     */
    PF_DimensionAttribute(const PF_Vector& definitionPoint,
                     const PF_Vector& middleOfText,
                     LX_Define::VAlign valign,
                     LX_Define::HAlign halign,
                     LX_Define::TextLineSpacingStyle lineSpacingStyle,
                     double lineSpacingFactor,
                     QString text,
                     QString style,
                     double angle) {
        this->definitionPoint = definitionPoint;
        this->middleOfText = middleOfText;
        this->valign = valign;
        this->halign = halign;
        this->lineSpacingStyle = lineSpacingStyle;
        this->lineSpacingFactor = lineSpacingFactor;
        this->text = text;
        this->style = style;
        this->angle = angle;
    }

    friend class PF_Dimension;
    friend class PF_DimAligned;
    friend class PF_DimLinear;
    friend class WF_DimAligned;
    friend class WF_DimLinear;

    friend std::ostream& operator << (std::ostream& os,
                                      const PF_DimensionAttribute& dd) {
        os << "(" << dd.definitionPoint << ")";
        return os;
    }


public:
    /** Definition point */
    PF_Vector definitionPoint;
    /** Middle point of dimension text */
    PF_Vector middleOfText;
    /** Vertical alignment */
    LX_Define::VAlign valign;
    /** Horizontal alignment */
    LX_Define::HAlign halign;
    /** Line spacing style */
    LX_Define::TextLineSpacingStyle lineSpacingStyle;
    /** Line spacing factor */
    double lineSpacingFactor;
    /**
    * Text string entered explicitly by user or null 
    * or "<>" for the actual measurement or " " (one blank space) 
    * for supressing the text. 
    */
    QString text;
    /** Dimension style name */
    QString style;
    /** Rotation angle of dimension text away from default orientation */
    double angle;
};



/**
 * Abstract base class for dimension entity classes.
 *

 */
class LX_EXPORT PF_Dimension : public PF_Container {
public:
    PF_Dimension(PF_Container* parent,
                 const PF_DimensionAttribute& d);
    virtual ~PF_Dimension() {}

    /** @return Copy of data that defines the dimension. */
    PF_DimensionAttribute getData() const {
        return data;
    }
	
	PF_Vector getNearestRef(const PF_Vector& coord, double* dist);
	PF_Vector getNearestSelectedRef(const PF_Vector& coord, double* dist);

    QString getLabel(bool resolve=true);
        void setLabel(const QString& l);

    /**
     * Needs to be implemented by the dimension class to return the
     * measurement of the dimension (e.g. 10.5 or 15'14").
     */
    virtual QString getMeasuredLabel() = 0;

    /**
     * Must be overwritten by implementing dimension entity class
     * to update the subentities which make up the dimension entity.
     */
    virtual void update(bool autoText=false) = 0;

    void updateCreateDimensionLine(const PF_Vector& p1, const PF_Vector& p2,
	          bool arrow1=true, bool arrow2=true, bool autoText=false);

    PF_Vector getDefinitionPoint() {
        return data.definitionPoint;
    }

    PF_Vector getMiddleOfText() {
        return data.middleOfText;
    }

    LX_Define::VAlign getVAlign() {
        return data.valign;
    }

    LX_Define::HAlign getHAlign() {
        return data.halign;
    }

    LX_Define::TextLineSpacingStyle getLineSpacingStyle() {
        return data.lineSpacingStyle;
    }

    double getLineSpacingFactor() {
        return data.lineSpacingFactor;
    }

    QString getText() {
        return data.text;
    }

    QString getStyle() {
        return data.style;
    }

    double getAngle() {
        return data.angle;
    }

    double getArrowSize();
    double getExtensionLineExtension();
    double getExtensionLineOffset();
    double getDimensionLineGap();
    double getTextHeight();
	
        double getGraphicVariable(const QString& key, double defMM, int code);

	virtual double getLength() {
		return -1.0;
	}

    virtual void move(PF_Vector offset);
    virtual void rotate(PF_Vector center, double angle);
    virtual void scale(PF_Vector center, PF_Vector factor);
    virtual void mirror(PF_Vector axisPoint1, PF_Vector axisPoint2);

protected:
    /** Data common to all dimension entities. */
    PF_DimensionAttribute data;
};

#endif
